*********************************
*** JOP paper: Historical memory and radical right voting: VOX and the legacy of Francoism
*** Anja Neundorf and Sergi Pardos-Prado
*** Do-file: DATA ANALYES MAIN PAPER
*** Analysis + Data Analsis VOX Paper
*** Created: 21/02/2022
*** Last updated: 21/03/2024

*** Operating system: MacOS Sonoma 14.4 
*** Statistical software: Stata MP 18.0 for Mac

clear all
capture log close

// Installing neccesary ados
ssc instal blindschemes
ssc instal coefplot
ssc instal outreg2

// Set scheme for graphs
set scheme plotplain

// Opening log file
log using "Main analyses.log", replace
 

*** SET DIRECTORY WHERE FILES ARE SAVED. THIS NEEDS TO BE CHANGED!!!

global		main "/Users/anja.neundorf/Library/CloudStorage/Dropbox/Project_Populism/Vox/Analysis/Replication"
global results "${main}/tables/"
global 		graphs 			"${main}/graphs/"

cd "${main}"


** Recode raw data
do "Vox_DataPrep.do" 

** Call recoded data
use "Spain_Vox_recoded.dta", clear 

*-------------------
*** Defining globals

global controls age female i.educ polint income i.b4.domicile
global vox  vote_3 vox_sup vote_vox_right
global ptv ptv_1 ptv_2 ptv_3 ptv_4 ptv_5
global outcomes_main support donate
global outcomes demimp01 autoc_dum 

bys vote_3: pwcorr $outcomes_main $outcomes

** ----------------------------------------------------------
** FIGURE 1: Plotting coef of treatments for sub-samples


foreach k of varlist vox_sup vote_3 {
reg support i.treat female i.educ if `k'==1
estimates store M1_`k'

reg donate i.treat female i.educ  if `k'==1 
estimates store M2_`k' 

reg support i.treat polint if `k'==0
estimates store M4_`k'

reg donate i.treat polint  if `k'==0 
estimates store M3_`k'

}

matrix list e(b)


coefplot  (M1_vox_sup, label(VOX supporters) msize(medlarge)  mlwidth(medthick)) (M1_vote_3, label(VOX voters) msize(medlarge)  mlwidth(medthick)) (M4_vote_3, label(Non-VOX voters) msize(medlarge)  mlwidth(medthick)), keep(1.treat 2.treat 3.treat 4.treat 5.treat) xline(0) xlabel() ylabel(, labsize(large))  xtitle("Marginal effects of treatments vs control ", size(large)) title(Outcome: Attitudinal Support, size(vlarge)) name(dv1, replace) legend(size(medium)) 

coefplot  (M2_vox_sup, label(VOX supporters) msize(medlarge)  mlwidth(medthick)) (M2_vote_3, label(VOX voters) msize(medlarge)  mlwidth(medthick)) (M3_vote_3, label(Non-VOX voters) msize(medlarge)  mlwidth(medthick)), keep(1.treat 2.treat 3.treat 4.treat 5.treat) xline(0) xlabel()  xtitle("Marginal effects of treatments vs control ", size(large)) title(Outcome: Donation, size(vlarge)) name(dv2, replace) legend(size(medium)) ylabel(, labsize(large))

graph combine dv1 dv2, xsize(11) ysize(5) 
graph save  "${graphs}Figure1_Coef_vox_treat.gph",  replace
graph export  "${graphs}Figure1_Coef_vox_treat.pdf", as(pdf) replace



** ----------------------------------------------------------
** TABLE 1: Main regressions - Using VOX-VOTE FOR INTERACTION

capture erase "${results}Table1_main_support.xls"
capture erase "${results}Table1_main_support.txt"

**  ON ENTIRE SAMPLE

foreach k of varlist vote_3 {
reg support i.treat##i.`k' polint 
estimates store M1_`k'
outreg2  using "${results}Table1_main_support.xls", ///
bracket bdec(3) sdec(3) append label word 

reg donate i.treat##i.`k' polint 
estimates store M2_`k'
outreg2  using "${results}Table1_main_support.xls", ///
bracket bdec(3) sdec(3) append label word 

}

** ON RIGHT-WING SAMPLE

foreach k of varlist vote_vox_right {
reg support i.treat##i.`k'
estimates store M1_`k'
outreg2  using "${results}Table1_main_support.xls", ///
bracket bdec(3) sdec(3) append label word 

reg donate i.treat##i.`k'  
estimates store M2_`k'
outreg2  using "${results}Table1_main_support.xls", ///
bracket bdec(3) sdec(3) append label word 

}


** ----------------------------------------------------------
** FIGURE 2:  Using VOX vote for interaction ON SUPPORT

bys vote_3: sum support if treat==1


*** Predicted values: SUPPORT

reg support i.treat##i.vote_3  polint
estimates store M1_vote

estimates restore M1_vote
margins,  at(treat= 1 vote_3 =(0(1)1))  
marginsplot, ///
yline(3.5) xtitle("VOX vote", size(vlarge)) ylabel(1(1)6, labsize(large)) xlabel(, noval labsize(medlarge)) ytitle(Predicted support, size(vlarge)) title(" ") legend(off) name(franco, replace) title("Pro-Franco", size(huge)) recastci(rspike) recast(scatter) plot1opts(msize(vlarge)  mlwidth(medthick))

estimates restore M1_vote
margins,  at(treat= 2 vote_3 =(0(1)1))  
marginsplot, ///
yline(3.5) xtitle("VOX vote", size(vlarge)) ylabel(1(1)6, labsize(large)) xlabel(, noval labsize(medlarge)) ytitle(Predicted support, size(vlarge)) title(" ") legend(off) name(catalan, replace) title("Pro-Catalan", size(huge)) recastci(rspike) recast(scatter) plot1opts(msize(vlarge) mlwidth(medthick))

estimates restore M1_vote
margins,  at(treat= 3 vote_3 =(0(1)1))  
marginsplot, ///
yline(3.5) xtitle("VOX vote", size(vlarge)) ylabel(1(1)6, labsize(large)) xlabel(, noval labsize(medlarge)) ytitle(Predicted support, size(vlarge)) title(" ") legend(off) name(immig, replace) title("Pro-Immigration", size(huge)) recastci(rspike) recast(scatter) plot1opts(msize(vlarge) mlwidth(medthick))


estimates restore M1_vote
margins,  at(treat= 4 vote_3 =(0(1)1))  
marginsplot, ///
yline(3.5) xtitle("VOX vote", size(vlarge)) ylabel(1(1)6, labsize(large)) xlabel(, noval labsize(medlarge)) ytitle(Predicted support, size(vlarge)) title(" ") legend(off) name(femin, replace) title("Pro-Feminism", size(huge)) recastci(rspike) recast(scatter) plot1opts(msize(vlarge) mlwidth(medthick))


estimates restore M1_vote
margins,  at(treat= 5 vote_3 =(0(1)1))  
marginsplot, ///
yline(3.5) xtitle("VOX vote", size(vlarge)) ylabel(1(1)6, labsize(large)) xlabel(, noval labsize(medlarge)) ytitle(Predicted support, size(vlarge)) title(" ") legend(off) name(union, replace) title("Pro-Unions", size(huge)) recastci(rspike) recast(scatter) plot1opts(msize(vlarge) mlwidth(medthick))
 
 graph combine  franco catalan immig femin union, xsize(11) ysize(4) row(1)
graph save  "${graphs}Figure2_Support_Voxvote_pred.gph",  replace
graph export  "${graphs}Figure2_Support_Voxvote_pred.pdf", as(pdf) replace

 
****---------------------------------
*** FIGURE 3: COHORTS

*** Continues birth year interaction 

reg support i.treat##i.vote_3##c.birth polint 

margins,  at(treat= 1  birth=(1945(1)2000) vote_3 =(0(1)1))  
marginsplot, ///
yline(3.5) xtitle("Birth year", size(medlarge)) ylabel(1(1)6, labsize(medium)) xlabel(1945(5)2000, labsize(medium) angle(45)) ytitle(Predicted support for Franco Foundation, size(medlarge)) recastci(rspike) recast(scatter)  legend(lab(3 "Non-VOX voters") lab(4 "VOX voters") size(medlarge) order(3 4 ) row(1) region(lcolor(white)) pos(2) ring(0)) title(" ")
graph save  "${graphs}Figure3_Margins_Voxvote_pred_coh_cont.gph",  replace
graph export  "${graphs}Figure3_Margins_Voxvote_pred_coh_cont.pdf", as(pdf) replace

log close
